<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="/pingzheng_js_css_img/jquery.min.js"></script>
<link href="/pingzheng_js_css_img/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/pingzheng_js_css_img/common.css" rel="stylesheet" type="text/css">
<link href="/pingzheng_js_css_img/style.css" rel="stylesheet" type="text/css">
<script src="${ctx}/component/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript">
	
	function initselect(clickObj){
		var div = '';
		$.post("${ctx}/dickm/getDickmByLikeCodeOrName", {dicCodeOrName : $.trim(clickObj.find(".text-auto").val())}, function(result) {
			if(result!=null && result!=undefined){
				$.each( $(result), function(i, obj){
					div+='<div class="div-li" kmCode="'+obj.dicCode+'" kmName="'+obj.fullName+'" >'+obj.dicCode+' '+obj.fullName+'</div>';
				});
				
				$(".div-ui").show();
				
				$(".div-ui").empty();
				$(".div-ui").append(div);
				$(".div-ui").width(clickObj.innerWidth()-2); 
				$(".div-ui").offset({ top: clickObj.offset().top+clickObj.innerHeight()});
				$(".div-ui").offset({ left: clickObj.offset().left});
				
				$(".div-li").hover(
					function () {
				   		$(this).addClass("hover");
				  	},
				  	function () {
					  $(this).removeClass("hover");
				  	}
				);
				
				$(".div-li").on("mousedown", function(){
					
				  clickObj.text($(this).text());
				  clickObj.attr("kmCode",$(this).attr("kmCode"));
				  clickObj.attr("kmName",$(this).attr("kmName"));
				  
				  clickObj.removeClass("v-edit");
				  $(".div-ui").hide();
				});
				
			}
		}, "json");
	}
	
	
	function jieDaiMoney(){
		var jieMoney=0;
		var daiMoney=0;
		$.each($("tbody .v-money"), function(i, obj){
			if($(obj).hasClass("v-money2")){
				if($(obj).text()!="" && $(obj).text() !=null){
					daiMoney+=parseFloat($(obj).text());
				}
			}else{
				if($(obj).text()!="" && $(obj).text() !=null){
					jieMoney+=parseFloat($(obj).text());
				}
			}
		});
		
		if(jieMoney==daiMoney){
			$("#hejizw").text(intToChinese(jieMoney));
			$("#hja").css("color","");
			
			var hj = jieMoney;
			if(jieMoney==0){
				hj = '000';
			}
			
			$("tfoot .v-money").html('<div class="v-data">'+hj+'</div>');
			$("tfoot .v-money").css("color","#39f");
			return true;
		}else{
			$("#hejizw").text("不平");
			$("#hja").css("color","#f33");
			
			$("tfoot .v-money").html('<div class="v-data">000</div>');
			$("tfoot .v-money").css("color","#f33");
			return false;
		}
	}
	
	function intToChinese(n) {
		n += '';
        if (!/^(-?[0-9]\d*)$/.test(n))
            return "——";
        if (n * 1 == 0) {
            return '零元整';
        }
        var fu = "";
        if (n * 1 < 0) {
            fu = "负";
            n = n.substring(1);
        }
        var unit = "仟佰拾亿仟佰拾万仟佰拾元角分",
            str = "";
        unit = unit.substr(unit.length - n.length);
        for (var i = 0; i < n.length; i++)
            str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
        var str1 = str.replace(/零(仟|佰|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整");
        return fu + str1;
	}
	
</script>

<script type="text/javascript">
	$(function(){
		//结算合计
		jieDaiMoney();
		
		$(".closeBtn").click(function() {
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		});
		
	});
	
</script>
</head>
<body>
	<div class="viewVcloud-main-body container vc">
		<div id="mainbodyVouchers" class="page-wrap">
			<form id="vouchersForm" class="form-inline">
				<div class="titlebread" style="height: 56px;">
					<div class="pull-right">
						<button id="saveAndNewVoucher2" type="button" style="background-color: red;border-color: red;font-size: 15px;" class="bluetbn-btn small-btn closeBtn">关闭</button>
						<button id="printVoucher2" type="button" class="lightblue-btn small-btn" style="display: none;">打印</button>
						<span class="lightblue-btn small-btn glyphicon glyphicon-retweet togglebtn isNotAdd" style="top: 0px; display: none;"></span>
					</div>
					<div class="voucher_tit">
						<h1>记账凭证</h1>
						<span class="vch_year_month" style="display: none;">xxxx-xx</span> <span></span>
					</div>
					<div class="forV">
						<span class="serialNum"> <span>凭证字</span> <input readonly="" class="form-control serPrefix" value="记" id="pzz" style="width: 58px;"> <input id="vouchersNumber" type="text" value="${pingZheng.pzhStr }" class="form-control serSuffix" readonly="readonly" style="width: 58px;background-color: #eee;">
							<span>号</span>
						</span> <label for="voucherDate" style="margin-left: 20px;">日期 ：</label>
						<div class="input-group input-append date form_datetime_v">
							<input class="form-control width-100" readonly="readonly" value="${pingZheng.pzDateStr }" id="voucherDate">
						</div>
						<input type="hidden" name="uuid" id="uuid" value="${pingZheng.uuid}" />
					</div>
					<div id="tag"></div>
				</div>
				<div class="form" style="margin-left: -30px;">
					<table class="table table-striped v-table" id="voucherTable">
						<colgroup>
							<col width="30">
							<col width="">
							<col width="349">
							<col width="219">
							<col width="219">
						</colgroup>
						<thead>
							<tr>
								<th class="table-edge"></th>
								<th style="vertical-align: middle;">
									<strong>摘要</strong>
								</th>
								<th style="vertical-align: middle;">
									<strong>会计科目</strong>
								</th>
								<th style="vertical-align: middle;">
									<strong>借方金额</strong>
									<div class="money_unit">
										<span>亿</span> <span>千</span> <span>百</span> <span>十</span> <span>万</span> <span>千</span> <span>百</span> <span>十</span> <span>元</span> <span>角</span> <span class="last">分</span>
									</div>
								</th>
								<th>
									<strong>贷方金额</strong>
									<div class="money_unit">
										<span>亿</span> <span>千</span> <span>百</span> <span>十</span> <span>万</span> <span>千</span> <span>百</span> <span>十</span> <span>元</span> <span>角</span> <span class="last">分</span>
									</div>
								</th>
							</tr>
						</thead>
						<tbody>
						
						<c:forEach items="${pingZheng.pzcList }" var="obj" varStatus="in">
							<tr data-id="${in.index+1 }" class="voucher-tr">
								<td class="table-edge" align="center"></td>
								<td data-type="brief">${obj.zyJl}</td>
								<td data-type="km" kmCode="${obj.kmdm}" kmName="${obj.kmmc}">${obj.kmdm} ${obj.kmmc}</td>
								<td data-type="money" class="v-money">${obj.jfjeStr}</td>
								<td data-type="money" class="v-money v-money2">${obj.dfjeStr}</td>
							</tr>
						</c:forEach>
						
						</tbody>
						<tfoot>
							<tr>
								<td class="table-edge"></td>
								<td colspan="2" class="heji" style="vertical-align: middle;">
									<strong id="hja">&nbsp;&nbsp;合计：<span id="hejizw"></span></strong>
								</td>
								<td class="v-money"></td>
								<td class="v-money"></td>
							</tr>
						</tfoot>
					</table>
				</div>
			</form>
		</div>
		<!-- 凭证页面 -->
		<div class="div-ui"></div>
</body>
</html>